import { useUserStore, useAdminStore } from '@/stores'
import instance from '@/utils/airequest'
const UserStore = useUserStore()
const AdminStore = useAdminStore()
const token = UserStore.token || AdminStore.token
const defaultHeaders = {
  'Content-Type': '/; charset=utf-8',
  token: token // 设置token请求头
}

//测试链接
export const aiTestLinkService = () => {
  return fetch('/api/qwenChat/test', {
    method: 'GET',
    headers: {
      ...defaultHeaders
    }
  })
}

//简单测试流式响应
export const aiTestStreamService = () => {
  // 使用fetch API发送请求
  return fetch('/api/qwenChat/test-stream', {
    method: 'GET',
    headers: {
      ...defaultHeaders
    }
  })
}

//逐字测试流式响应
export const aiTestStreamCharService = () => {
  // 使用fetch API发送请求
  return fetch('/api/qwenChat/test-char-stream', {
    method: 'GET',
    headers: {
      ...defaultHeaders
    }
  })
}

//流式聊天接口
export const aiStreamCharService = (obj) => {
  const { userId, userMessage, chatId } = obj
  const queryParams = new URLSearchParams({ userMessage, chatId })
  const url = `/api/qwenChat/chat/${userId}?${queryParams.toString()}`
  return fetch(url, {
    method: 'POST',
    headers: {
      ...defaultHeaders
    }
  })
}

//获取指定会话的聊天记录
export const aiBlockHistoryService = (obj) => {
  const { userId, chatId } = obj
  return instance.get(`/qwenBlock/history/${userId}/${chatId}`)
}

//获取聊天记录列表
export const aiBlockHistoryListService = (userId) => {
  return instance.get(`/qwenBlockFW/history/${userId}`)
}

//删除指定会话
export const aiDeleteHistoryService = (obj) => {
  const { userId, chatId } = obj
  return instance.delete(`/qwenBlockFW/history/${userId}/${chatId}`)
}
